package com.zfei.gfb.controller;

import com.google.common.collect.Lists;
import com.zfei.gfb.bean.Const;
import com.zfei.gfb.core.HttpJson;
import com.zfei.gfb.core.LogResult;
import com.zfei.gfb.dao.GfbNoticeMapper;
import com.zfei.gfb.model.GfbNotice;
import com.zfei.gfb.query.GfbNoticeQuery;
import com.zfei.gfb.util.Beans;
import com.zfei.gfb.util.Now;
import com.zfei.gfb.vo.GfbNoticeListVo;
import com.zfei.gfb.vo.GfbNoticeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author
 * @version 1.0
 */
@Api(tags = "H5通知公告接口")
@RestController
@RequestMapping("/h5/notice")
public class H5NoticeController {

    @Resource
    private GfbNoticeMapper gfbNoticeMapper;

    @ApiOperation(value = "列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "列表",response = GfbNoticeListVo.class),
    })
    @LogResult
    @HttpJson("/list")
    public Object list(@RequestBody GfbNoticeQuery query) {
        if(query.getPageNo() != null){
            query.build(Now::millis);
        }
        //全部


        query.setStatus(Const.STATUS_ON);

        GfbNoticeListVo result = new GfbNoticeListVo();

        int total = gfbNoticeMapper.total(query);

        result.setTotal(total);
        if (total == 0) {
            result.setData(Lists.newArrayList());
            return result;
        }

        List<GfbNotice> list = gfbNoticeMapper.list(query);
        List<GfbNoticeVo> gfbNoticeVos = Beans.copys(list, GfbNoticeVo.class);
        result.setData(gfbNoticeVos);

        return result;
    }

}
